import os

from django.apps import AppConfig
from apscheduler.schedulers.background import BackgroundScheduler

from AchieveHandler.service.achieve_handler import backup_material

class AchieveHandlerConfig(AppConfig):
    default_auto_field = "django.db.models.BigAutoField"
    name = "AchieveHandler"

    def ready(self):
        scheduler = BackgroundScheduler()
        if os.environ.get('RUN_MAIN'):
            scheduler = BackgroundScheduler()
            scheduler.add_job(backup_material, 'cron', hour=10, minute=0, id='achieve_material')
            scheduler.start()